<template>
  <div class="count-warn">
    <div class="warn-wrap">
      <p>报警总数</p>
      <!-- 分类展示 -->
      <div class="warn-legend">
        <div v-for="(item, i) in convertList" :key="i" @click="showAlarmByType(i, $event)"><span :class="item[0].moduleCode"></span><i>{{ item[0].moduleName }}</i></div>
      </div>
      <!-- 分类占比 -->
      <!--<ul class="type-length clearfix">-->
        <!--<template v-for="(item, key, i) in convertList">-->
          <!--<li :style="{background: chooseColor(i), width: chooseWidth(item.length)}"></li>-->
        <!--</template>-->
      <!--</ul>-->
    </div>
    <div class="warn-all" @click="showAllAlarm">{{allCount}}</div>
  </div>
</template>

<script>
export default {
  name: 'countWarning',
  props: ['alarmList'],
  data () {
    return {}
  },
  computed: {
    // 转换后的list
    convertList () {
      return this.mapListConvert(this.alarmList)
    },
    // 总数
    allCount () {
      let count = 0
      for (let i in this.convertList) {
        let item = this.convertList[i]
        count += item.length
      }
      return count
    }
  },
  mounted () {
    // console.log(this.$base.getConst('common', 'colorMore'));
    // this.showLength();
  },
  methods: {
    showAllAlarm () {
      this.$store.commit('setWarnData', this.alarmList)
      this.$store.commit('setWarnPopShow', true)
    },
    showAlarmByType (id) {
      this.$store.commit('setWarnData', this.convertList[id])
      this.$store.commit('setWarnPopShow', true)
    },
    // 地图列表数据转化
    mapListConvert (data) {
      let list = {}
      for (let item of data) {
        if (!list[item.moduleId]) {
          list[item.moduleId] = []
        }
        list[item.moduleId].push(item)
      }
      return list
    },
    chooseColor (i) {
      return this.$base.getConst('common', 'colorMore')[i]
    },
    chooseWidth (i) {
      let l = Object.getOwnPropertyNames(this.convertList).length // 获取种类数
      let w = Math.floor((i / this.allCount) * (234 - (l * 2)))
      return w + 'px'
    }
  }
}
</script>
<style scoped>
  .count-warn {
    position: relative;
    width: 100%;
  }

  .warn-wrap {
    position: relative;
    background: rgba(43, 54, 72, 0.95);
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    margin-bottom: 10px;
    padding: 18px;
    font-size: 12px;
  }

  .warn-legend {
    margin-top:10px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .warn-legend div {
    margin: 10px 0;
  }

  .warn-wrap p {
    color: #fff;
    width: 180px;
    margin-bottom: 15px;
  }

  .type-length {
    margin-top: 5px;
  }

  .type-length li {
    list-style: none;
    float: left;
    height: 10px;
    margin-right: 2px;
  }

  .warn-wrap i {
    font-style: normal;
    width: 100px;
    opacity: 0.8;
    font-size: 12px;
    line-height: 18px;
    cursor: pointer;
  }
  .warn-wrap i:hover {
    color:#409EFF;
  }

  .warn-wrap span {
    float: left;
    margin-right: 9px;
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    border-radius: 2px;
    font-size: 14px;
    width: 16px;
    text-align: center;
    line-height: 18px;
  }

  .warn-wrap .warn-legend div {
    width: 80px;
    line-height: 10px;
    color: #fff;
    margin-right: 30px;
  }

  .warn-all {
    color: #fff;
    font-size: 36px;
    position: absolute;
    right: 20px;
    top: 0;
    cursor: pointer;
    z-index: 9;
    cursor: pointer;
  }

  .warn-all:hover {
    color: #F5A623;
  }
</style>
